package com.star.star.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.star.security.annotations.Authorize;
import com.star.star.dto.StarAlbumArtPageWxuserDTO;
import com.star.star.dto.StarAlbumPageWxuserDTO;
import com.star.star.dto.StarAlbumSaveWxuserDTO;
import com.star.star.dto.StarAlbumUpdateWxuserDTO;
import com.star.star.service.StarAlbumArtService;
import com.star.star.service.StarAlbumService;
import com.star.star.service.StarArtService;
import com.star.star.vo.StarAlbumArtPageWxuserVO;
import com.star.star.vo.StarAlbumDetailWxuserVO;
import com.star.star.vo.StarAlbumPageWxuserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.star.core.base.BaseController;

/**
 * 艺人专辑
 *
 * @author yangzj
 */
@RestController
@RequestMapping("/star-album")
public class StarAlbumController extends BaseController {

    @Autowired
    private StarAlbumService starAlbumService;
    @Autowired
    private StarAlbumArtService starAlbumArtService;

    //-------------------- 以下微信小程序（用户端）接口 --------------------

    /**
     * 保存-微信小程序（用户端）
     *
     * @param dto    入参
     */
    @Authorize("wxuser")
    @PostMapping("/wxuser")
    public void saveWxuser(@Validated @RequestBody StarAlbumSaveWxuserDTO dto){
        starAlbumService.saveWxuser(dto, getUserId());
    }

    /**
     * 更新-微信小程序（用户端）
     *
     * @param dto 入参
     */
    @Authorize("wxuser")
    @PutMapping("/wxuser")
    public void updateWxuser(@Validated @RequestBody StarAlbumUpdateWxuserDTO dto){
        starAlbumService.updateWxuser(dto, getUserId());
    }

    /**
     * 删除通过ID-微信小程序（用户端）
     *
     * @param id ID
     */
    @Authorize("wxuser")
    @DeleteMapping("/wxuser/{id}")
    public void deleteByIdWxuser(@PathVariable("id") Long id){
        starAlbumService.deleteByIdWxuser(id, getUserId());
    }

    /**
     * 分页-微信小程序（用户端）
     *
     * @param dto 入参
     * @return {@link IPage}<{@link StarAlbumPageWxuserVO}>
     */
    @Authorize("wxuser")
    @PostMapping("/wxuser/page")
    public IPage<StarAlbumPageWxuserVO> pageWxuser(@Validated @RequestBody StarAlbumPageWxuserDTO dto){
        return starAlbumService.pageWxuser(dto.setUserId(getUserId()));
    }

    /**
     * 获取详情-微信小程序（用户端）
     *
     * @param id     ID
     * @return {@link StarAlbumDetailWxuserVO}
     */
    @Authorize("wxuser")
    @GetMapping("/wxuser/{id}")
    public StarAlbumDetailWxuserVO getDetailWxuser(@PathVariable("id") Long id){
        return starAlbumService.getDetailWxuser(id, getUserId());
    }

    /**
     * 专辑下作品分页-微信小程序（用户端）
     *
     * @param dto 入参
     * @return {@link IPage}<{@link StarAlbumPageWxuserVO}>
     */
    @Authorize("wxuser")
    @PostMapping("/wxuser/art/page")
    public IPage<StarAlbumArtPageWxuserVO> pageArtWxuser(@Validated @RequestBody StarAlbumArtPageWxuserDTO dto){
        return starAlbumArtService.pageWxuser(dto.setUserId(getUserId()));
    }
}
